@extends('layouts.appDomain')

@section('content')
<div class="container py-5">
    <div class="row justify-content-center">
        <div class="col-12">
            <div class="card panel mb-4">
                <div class="card-header">角色升级 - {{$character->name}} - Lv {{$character->level}}</div>

                <div class="card-body">
                	<form action="/user/levelUpDo" method="get" onsubmit="return checkForm();">
                		<input type="hidden" name="type" value="2">
                		<input type="hidden" class="moneyForPerLevel" value="{{config('conf.serverDef.moneyForPerLevel')}}">
                		<input type="hidden" name="server_id" value="{{$server->id}}">
                		<input type="hidden" name="user_id" value="{{$server->user_id}}">
                		<input type="hidden" name="character_id" value="{{$character->guid}}">
                		<input type="hidden" name="character_name" value="{{$character->name}}">
	                	<div class="row col-12">
	                		<div class="col-6">	
		                		<div class="input-group mt-2">
							        <div class="input-group-prepend">
							          <div class="input-group-text">请输入您的目标级数</div>
							        </div>
							        <input type="hidden" value="{{$character->level}}" class="level" name="level">
							        <input type="number" class="form-control" id="desLevel" name="desLevel">
						        </div>
		                	</div>

		                	<div class="col-6">
		                		<div class="input-group mt-2">
							        <div class="input-group-prepend">
							          <div class="input-group-text">预计费用(积分)</div>
							        </div>
							        <input type="text" class="form-control" id="price" readonly>
						        </div>
		                	</div>
		                	<div class="col-12  mt-2">
			                	<span class="text-danger" onclick="location='/user/recharge'">积分不足，点我充值吧</span>
		                	</div>
	                	</div>  


	                	
	                	<div class="text-center mt-5">
	                		<button class="btn btn-info" type="submit">立即购买</button>
	                	</div>            	
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
	$('#desLevel').on('keyup change',function(){
		$(this).val($(this).val().replace(/\D|^0/g,''));
		var moneyForPerLevel = $('.moneyForPerLevel').val();
		var level = $('.level').val();
		var desLevel = $(this).val();
		var price = (desLevel - level)*moneyForPerLevel;
		if (desLevel > 80) {
			$('#price').val('最高只能升到80级哦');
		} else {
			if (price > 0) {
				$('#price').val(price);
			} else {
				$('#price').val('请保证目标级数大于您当前的级数');
			}
		}	
	});
	function checkForm(){
		var level = $('.level').val();
		var desLevel = $('#desLevel').val();
		if (desLevel > 80) {
			alert('最高只能升到80级哦');
			return false;
		} else if (desLevel < level) {
			alert('请确保升级级数大于您的当前级数哦');
			return false;
		}
	}
</script>
@endsection